package io.renren.modules.basic.service.impl;

import io.renren.modules.basic.dao.MtCcProductDao;
import io.renren.modules.basic.entity.MtCcProductEntity;
import io.renren.modules.basic.service.MtCcProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;




@Service("mtCcProductService")
public class MtCcProductServiceImpl extends ServiceImpl<MtCcProductDao, MtCcProductEntity> implements MtCcProductService {

    @Autowired MtCcProductDao mtCcProductDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = String.valueOf(params.get("key"));
        IPage<MtCcProductEntity> page =null;
        if (key.equals("")){
            page = this.page(
                    new Query<MtCcProductEntity>().getPage(params),
                    new QueryWrapper<MtCcProductEntity>()
            );
        }else {
            String keyFeature = String.valueOf(params.get("key")).substring(1, 2);
            if (keyFeature.equals(".")){
                page = this.page(
                        new Query<MtCcProductEntity>().getPage(params),
                        new QueryWrapper<MtCcProductEntity>().eq("product_code",key)
                );
            }else {
                page = this.page(
                        new Query<MtCcProductEntity>().getPage(params),
                        new QueryWrapper<MtCcProductEntity>().eq("product_name",key)
                );
            }

        }


        return new PageUtils(page);
    }

    @Override
    public List<MtCcProductEntity> currentProductCount() {
        return mtCcProductDao.currentProductCount();
    }

}